package com.zhiche.lisa.tms.service;


import com.zhiche.lisa.core.utils.HttpClientUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class SendMsgService {
	
	static Logger logger = Logger.getLogger(SendMsgService.class);

	@Value("${wccyr.province_url}")
	private String PROVINCE_URL;

    public String sendToProvince(String xml){
    	try {

			String response = HttpClientUtil.postXml(PROVINCE_URL, xml);
    		logger.info("sendToProvince response:" + response);
			return response;
		} catch (Exception e) {			
			e.printStackTrace();
			logger.info("向省平台接口发送报文异常：" + e.getMessage());	
			return "";
		}
    }
    
//	public static String soapMsg(String xml, String token) throws UnsupportedEncodingException {
//
//		String uuid = UUID.randomUUID().toString();
//		String soapMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
//				+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" "
//				+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
//				+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
//				+ " xmlns:ns6=\"http://schemas.egs.org.cn/businessdata\""
//				+ " xmlns:ns4=\"http://schema.egs.org.cn/exchange/cdt\""
//				+ " xmlns:ns5=\"http://schema.egs.org.cn/exchange/edf\""
//				+ " xmlns:ns1=\"http://service.egs.org.cn/exchange/exchangetransport\""
//				+ " xmlns:ns3=\"http://schema.egs.org.cn/exchange/exchangetransport\">"
//				+ "<SOAP-ENV:Header>"
//				+ "<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
//				+ "<wsse:UsernameToken>"
//				+ "<wsse:Username>" + ConfigConstant.TOKEN_USERID + "</wsse:Username>"
//				+ "<wsse:UserTokenID>ticket:"
//				+ token
//				+ "</wsse:UserTokenID>"
//				+ "</wsse:UsernameToken>"
//				+ "</wsse:Security>"
//				+ "</SOAP-ENV:Header>"
//				+ "<SOAP-ENV:Body>"
//				+ "<ns3:SendRequest xsi:type=\"ns3:SendRequestType\">"
//				+ "<ns3:ToAddress>wcjc0001</ns3:ToAddress>"
//				+ "<ns3:ExchangeEvent xsi:type=\"ns3:ExchangeEventType\" "
//				+ " ActionType=\"" + ConfigConstant.EXCHANGE_ACTIONTYPE + "\""
//				+ " EventID=\"" + uuid + "\">"
//				+ "<ns5:ExchangeDataPackage title=\"sendpackage\" expireTime=\"2016-12-31T03:11:00Z\""
//				+ " createTime=\"2016-12-21T03:11:00Z\" transactionID=\"" + uuid + "\""
//				+ " packageID=\"" + uuid + "\" xsi:type=\"ns5:ExchangeDataPackageType\">"
//				+ "<ns5:ExchangeDataPackageUnit expireDate=\"2016-12-31T03:11:00Z\" createDate=\"2016-12-21T03:11:00Z\""
//				+ " entityDispName=\"unkown\" entityIDName=\"unkown\" source=\"xml stream\""
//				+ " unitID=\"{11B06B82-7223-4e33-8A7B-06893645C7F2}\" sequenceInGroup=\"1\" groupSize=\"1\""
//				+ " groupID=\"{01504AFE-016B-44fb-9C47-A9EBB1FB9507}\" xsi:type=\"ns5:ExchangeDataPackageUnitType\">"
//				+ "<ns5:DataFile dataFileFormat=\"XML\" fileName=\"filename.xml\" dataFileID=\"A60D4B72-CCBE-42f5-B4B9-52BA21426E30\""
//				+ " xsi:type=\"ns5:DataFileType\">" + "<ns5:Base64EncodedData>"
//				+ Base64Util.getBASE64(Base64Util.getBASE64(xml, "UTF-8")) + "</ns5:Base64EncodedData>"
//				+ "</ns5:DataFile>" + "</ns5:ExchangeDataPackageUnit>"
//				+ "</ns5:ExchangeDataPackage>" + "</ns3:ExchangeEvent>"
//				+ "</ns3:SendRequest>" + "</SOAP-ENV:Body>"
//				+ "</SOAP-ENV:Envelope>";
//
//		return soapMsg;
//	}
//
//	public static void main(String[] args) throws DocumentException {
//		String xml = NRtest.getMessageToXML();
//		String res = send(Base64Util.getBASE64(Base64Util.getBASE64(xml)));
//		Map resMap = Soap1_1client.getResponseMap(res);
//		System.out.println(res);
//		System.out.println("SendResult : " + resMap.get("SendResult"));
//
//	}
}
